package org.demo.algorithm.lagou.column.relearn;

import org.demo.algorithm.common.ListNode;

/**
 * 求奇数个数链表的中间位置
 */
public class LinkedMedian {

    public static Integer median(ListNode head) {
        if (null == head) {
            return null;
        }
        ListNode fast = head.next;
        ListNode slow = head;
        while (slow != null && fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        assert slow != null;
        return slow.val;
    }

}
